import dayjs from "dayjs";
import dshUtils from "dsh-utils";

export const times = [
  '8',
  '9',
  '10',
  '11',
  '12',
  '13',
  '14',
  '15',
  '16',
  '17',
  '18'
]


export const minutes = [
  '00',
  '15',
  '30',
  '45',
]


export const handelEvents = (events) => {
  let eventsTimes = [];
  events.forEach((item) => {
    item.start = item.start.replace(/-/g, '/')
    item.end = item.end.replace(/-/g, '/')
    const startTime = new Date(item.start);
    const endTime = new Date(item.end);
    const res = dshUtils.getDateArray(startTime, endTime, 15).reverse();
    res.pop();
    const temArr = [];
    res.forEach((r, index) => {
      if (index === 0) {
        temArr.push({
          id: item?.id,
          color: item.color,
          t: dayjs(r).format("YYYY-MM-DD H:mm"),
          info: item.info,
        });
      } else {
        temArr.push({
          color: item.color,
          id: item?.id,
          t: dayjs(r).format("YYYY-MM-DD H:mm"),
        });
      }
    });
    // eventsTimes = (res.map(item=>dayjs(item).format('YYYY-MM-DD H:mm')).reverse());
    eventsTimes = [...temArr, ...eventsTimes];
  });
  return eventsTimes;
};

// 随机颜色
export const getColor = () => {
  const r = Math.floor(Math.random() * 255);
  const g = Math.floor(Math.random() * 255);
  const b = Math.floor(Math.random() * 255);
  return {
    backgroundColor: `rgba(${r},${g},${b},0.2)`,
    borderLeft: `6rpx solid rgba(${r},${g},${b})`,
  };
};